package com.cet.kafkaproducer.config;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @program: cet-practice
 * @description:
 * @author: 陈恩涛
 * @create: 2023-07-24 22:39
 **/
public class CetPartition implements Partitioner {

    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {

        if(key instanceof String) {
            String keyStr = (String) key;
            if(keyStr.contains("cet")) {
                return 1;
            } else {
                return 2;
            }
        }
        return 0;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
